package map;

import java.util.*;

public class MapDemo2 {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("语文",60);
        map.put("数学",30);
        map.put("英语",99);
        map.put("物理",99);
        map.put("化学",98);
        System.out.println(map);

        Set<String> keySet = map.keySet();
        for (String key : keySet){
            System.out.println("key:"+key);
        }

        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        for (Map.Entry<String,Integer> e : entrySet){
            String key = e.getKey();
            Integer value = e.getValue();
            System.out.println(key+":"+value);
        }

        Collection<Integer> values = map.values();
        for (Integer value : values){
            System.out.println("value:"+value);
        }

        Collection<String> c = new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");
        c.add("six");
        //新循环
        for (String s : c){
            System.out.println(s);
        }
        //forEach
        c.forEach(s -> System.out.println(s));
        //Map也支持forEach方法
        map.forEach((k,v) -> System.out.println(k+","+v));
    }
}
